package com.longway.core.ext.excel.error;

import java.text.MessageFormat;

public class ErrorException extends Exception
{
    private static final long serialVersionUID = -57777366986121930L;
    private Integer errcode;
    private boolean throwParent;
    private Object[] formatParams;

    public ErrorException(int errcode)
    {
        super();
        this.errcode = errcode;
        throwParent = false;
    }

    public ErrorException(int errcode, Object[] params)
    {
        super();
        this.errcode = errcode;
        throwParent = false;
        formatParams = params;
    }

    public ErrorException(java.lang.Throwable arg0)
    {
        super(arg0);
        throwParent = true;
    }

    public ErrorException(int errcode, java.lang.Throwable arg0)
    {
        super(arg0);
        this.errcode = errcode;
        throwParent = true;
    }

    public String getErrorMessage()
    {
        if (errcode == null)
        {
            return this.getCause().getMessage();
        }

        String errmsg = "";
          ErrorCode errorCode = new ErrorCode();
          errmsg = errorCode.getMessage(errcode);

        if (throwParent) {
            errmsg = errmsg + " original message:" + this.getCause().toString();
        }

        if (formatParams != null)
        {
            MessageFormat.format(errmsg, formatParams);
        }

        return errmsg;
    }

    public Integer getErrcode()
    {
        return errcode;
    }
}

  
